package cn.edu.tsinghua.weibo.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.edu.tsinghua.weibo.action.WeiboAction;
import cn.edu.tsinghua.weibo.entity.User;

@SuppressWarnings("serial")
public class Profile extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
//		System.out.println("in profile servlet...");
		
		HttpSession session = request.getSession();
		if (session.getAttribute("user") == null) {//session失效，回index
			response.sendRedirect("index.jsp");
		} else {
//			int userid = Integer.parseInt(request.getParameter("userid"));//request的userid，不安全，要与session进行比对
//			System.out.println("userid: " + userid);//.
			//do something...
			session.setAttribute("result", WeiboAction.findWeiboByUserID(((User)session.getAttribute("user")).getId(), "user"));
			request.getRequestDispatcher("profile.jsp").forward(request, response);
		}
	}
	
}
